package com.esc.print.flutter_pda_print

import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.widget.TextView


/**
 * Created by moxiaomo
 * on 2021/3/13
 */
class LoadProgressDialog @JvmOverloads constructor(context: Context?, private var message: String, private val canCancel: Boolean = true) : Dialog(context!!, R.style.LoadProgressDialog) {
    private var textView: TextView? = null
    fun setMessage(message: String) {
        this.message = message
        handler.sendEmptyMessage(0)
    }

    @SuppressLint("HandlerLeak")
    private val handler: Handler = object : Handler() {
        override fun handleMessage(msg: Message) {
            if (msg.what == 0) {
                textView!!.text = message
            }
        }
    }

    @SuppressLint("ResourceType")
    override fun onCreate(savedInstanceState: Bundle) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.loading_layout)
        textView = findViewById(R.id.tv_message)
        //        setCancelable(canCancel);
        setCanceledOnTouchOutside(canCancel)
        textView?.setText(message)
    }
}